package com.edu.base.rest;

import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.edu.base.common.ParamsUtil;
import com.edu.base.ums.bannerPosition.domain.AdBannerPosition;
import com.edu.base.ums.bannerPosition.service.IAdBannerPositionService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.StringUtils;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import springfox.documentation.annotations.ApiIgnore;


/**
 *获得banner图接口 
 * @author lzs
 * @version 2021-04-08
 */
@ApiIgnore
@Api(tags = "广告位置相关接口",hidden = true)
@RestController
@RequestMapping("/api/bannerPosition")
public class AppBannerPositionController extends  BaseController {
	@Autowired
	private IAdBannerPositionService adBannerPositionService;
  	
	@Autowired
    private HttpServletRequest request;
	
	/**
	 * 获得轮播图列表 
	 * @param
	 * @return
	 */
	@GetMapping(value = "/findBannerPositionList") 
	@ApiOperation(value = "获得广告位置接口",response =AdBannerPosition.class)
    @ApiImplicitParams({
    	    @ApiImplicitParam(name = "positionName", value = "位置名称"), 
    	    @ApiImplicitParam(name = "preferentialDate", value = "优惠日期截止(格式为yyyy-MM-dd)"), 
       }) 
	public AjaxResult findBannerPositionList(HttpServletResponse res,String positionName,String preferentialDate) {
       
		List<String> list = ParamsUtil.listAllParams(request);
		if(!list.isEmpty()) {
			// 参数列中的parameter1、parameter2、parameter3等参数并未定义在参数列表中，为无效参数。
			list.remove("positionName"); 
			list.remove("preferentialDate");
 			if(list.size() > 10) {
				list = list.subList(0, 10);
			}
		}
  
		AdBannerPosition  abp = new  AdBannerPosition();
		abp.setPositionName(positionName);
		if(org.apache.commons.lang3.StringUtils.isNotBlank(preferentialDate)) { 
			abp.setPreferentialDate(DateUtils.dateTime(DateUtils.YYYY_MM_DD_HH_MM_SS, preferentialDate));
		} 
    		
 		List<AdBannerPosition> abplist = adBannerPositionService.selectAdBannerPositionList(abp);
   		
		String msg = ""; 
		String param = String.join("、",list);
        if(StringUtils.isNotBlank(param)) {
        	msg += "参数列中的" + param +"等参数并未定义在参数列表中，为无效参数。";
        }
        if(StringUtils.isNotBlank(msg)) {
        	return AjaxResult.error(msg); 
        }
        
        return  AjaxResult.success(abplist);
	}

}
